package toanstt.mainframe;

import toanstt.com.App;
import toanstt.com.Button;
import toanstt.com.DiamondLinkinActivity;
import toanstt.com.SCR;
import toanstt.com.T;
import toanstt.gameplay.CellTable;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.media.ExifInterface;
import android.util.Log;
import android.view.MotionEvent;
import android.view.inputmethod.InputMethodManager;

public class MainFrame 
{
	Button but_timechange;
	Button but_stagechange;
	Button but_shop;
	Button but_howto;
	Button but_exit;
	int temp_x, temp_y;
	MenuPannel menupanel;
	public MainFrame()
	{
		//InputMethodManager imm = (InputMethodManager)DiamondLinkinActivity.activity.getSystemService(DiamondLinkinActivity.context.INPUT_METHOD_SERVICE);
		//imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
		//imm.hideSoftInputFromWindow(singleedittext.getWindowToken(),0);
		
		//InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
		//imm.hideSoftInputFromWindow(singleedittext.getWindowToken(),0); 
		menupanel = new MenuPannel();
		but_timechange = new Button(T.bitmap_button_timech, (int)(T.GAMESCREEN_MIN_X + 8*T.UNIT), (int)(T.GAMESCREEN_MIN_Y + 4*T.UNIT), 1.0f);
		but_stagechange = new Button(T.bitmap_button_stagech, (int)(T.GAMESCREEN_MIN_X + 22*T.UNIT), (int)(T.GAMESCREEN_MIN_Y + 5*T.UNIT), 1.0f);
		but_shop = new Button(T.bitmap_button_shop, (int)(T.GAMESCREEN_MIN_X + 8*T.UNIT), (int)(T.GAMESCREEN_MIN_Y + 15*T.UNIT), 1.0f);
		but_howto = new Button(T.bitmap_button_howto, (int)(T.GAMESCREEN_MIN_X + 22*T.UNIT), (int)(T.GAMESCREEN_MIN_Y + 16*T.UNIT), 1.0f);
		but_exit = new Button(T.bitmap_button_exit, (int)(T.GAMESCREEN_MIN_X + 25*T.UNIT), (int)(T.GAMESCREEN_MIN_Y + 25*T.UNIT), 0.5f);
		
	}
	public void Draw(Canvas canvas)
	{
		DrawMainFram(canvas);
		but_timechange.Draw(canvas);
		but_stagechange.Draw(canvas);
		but_shop.Draw(canvas);
		but_howto.Draw(canvas);
		but_exit.Draw(canvas);
		menupanel.Draw(canvas);
		//ResetAllMouseAlpha();
		//T.bitmapFont[0].drawString(canvas, "NGUYEN MAU TOAN", 200, 100, 0);
		//T.bitmapFont[1].drawString(canvas, "Nguyen Mau Toan", 200, 150, 0);
		//T.bitmapFont[2].drawString(canvas, "NGUYEN MAU TOAN", 200, 200, 0);
		//T.bitmapFont[3].drawString(canvas, "NGUYEN MAU TOAN", 200, 280, 0);
		//T.bitmapFont[4].drawString(canvas, "NGUYEN MAU TOAN", 200, 350, 0);
	}
	public void Update()
	{
		
	}
	protected void DrawMainFram(Canvas canvas)
	{
		

		
		int width_step=T.MARGIN_WIDTH;
		
		T.paint.setColor(Color.DKGRAY);
		canvas.drawRect(width_step, 0, width_step + T.BORDER_WIDTH, T.DISPLAY_HEIGHT, T.paint);
		
		width_step += T.BORDER_WIDTH;
		canvas.drawARGB(150, 0, 0,0);
	//	T.paint.setColor(Color.WHITE);
	//	canvas.drawRect(width_step, 0, width_step + T.GAME_SCREEN_WIDTH, T.GAME_SCREEN_HEIGHT, T.paint);
		
		
		width_step += T.GAME_SCREEN_WIDTH;
		T.paint.setColor(Color.DKGRAY);
		canvas.drawRect(width_step, 0, width_step + T.BORDER_WIDTH, T.DISPLAY_HEIGHT, T.paint);
		//draw menu
		
		T.mat = new Matrix();
		T.mat.postScale(T.MENU_WIDTH*1.0f/300,T.MENU_WIDTH*2.0f/600);
		T.mat.postTranslate(T.PANEL_MIN_X, T.PANEL_MIN_Y);
		canvas.drawBitmap(T.bitmap_frame_panel, T.mat, null);
		
	}
	public void touch(MotionEvent mo)
	{
		
		//Log.d("here", "ddddddd");
		int action = mo.getAction();
		int actionCode = action & MotionEvent.ACTION_MASK;
		temp_x = (int)mo.getX();
		temp_y = (int)mo.getY();
	
		if(but_timechange.Kick(mo) == true)
		{
			App.gamemanagement.NewGame(0, 60, 4);
			T.PLAY_ISTAGE = false;
			T.SCREEN = SCR.GAME;
			return;
		}
		else if(but_stagechange.Kick(mo) == true)
		{
			but_timechange.anpla = 255;
			App.gamemanagement.NewGame(T.PLAY_CURRENTSTAGE, 1, 4);
			T.PLAY_ISTAGE = true;
			T.SCREEN = SCR.GAME;
			return;
		}	
		else if(but_shop.Kick(mo) == true)
		{
			but_stagechange.anpla = 255;
			//T.notice.DoNotice();
			//App.gamemanagement.NewGame(1, 1, 1, 1);
			App.shop.ResetAllMouseAlpha();
			T.SCREEN = SCR.SHOP;
			return;
		}	
		else if(but_howto.Kick(mo) == true)
		{
			but_shop.anpla = 255;
			//App.gamemanagement.NewGame(1, 1, 1, 1);
			//T.SCREEN = SCR.GAME;
			return;
		}	
		else if(but_exit.Kick(mo) == true)
		{
			but_howto.anpla = 255;
			T.saveGame();
			DiamondLinkinActivity.activity.finish();
			
			return;
		}
		else
			but_exit.anpla = 255;
		//else
			//ResetAllMouseAlpha();
		if(actionCode == MotionEvent.ACTION_UP)
			ResetAllMouseAlpha();
	}
	public void ResetAllMouseAlpha()
	{
		but_timechange.anpla = 255;
		but_stagechange.anpla = 255;
		but_shop.anpla = 255;
		but_howto.anpla = 255;
		but_exit.anpla = 255;
	}
	
}
